package com.xltt.watchfota;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okserver.OkDownload;
import com.lzy.okserver.download.DownloadListener;

import java.io.File;

import com.xltt.fota.UpdateAppBean;
import com.xltt.watchfota.bean.ApkBean;

/**
 * Created by 55241 on 2017/9/8.
 * @author SJD
 */

public class DownloadFile {

    private DownloadListener downloadListener;

    public DownloadFile(DownloadListener downloadListener) {
        this.downloadListener = downloadListener;
    }

    public void startDownloadOkGo(ApkBean apk, String fileName, String filePath) {
        GetRequest<File> request = OkGo.<File>get(apk.url);
        //这里第一个参数是tag，代表下载任务的唯一标识，传任意字符串都行，需要保证唯一,我这里用url作为了tag
        OkDownload.request(apk.url, request)
                .priority(apk.priority)
                .fileName(fileName)
                .folder(filePath)
                .extra1(apk)
                .save()
                .register(downloadListener)
                .start();
    }

    public void restartDownloadOkGo(ApkBean apk, String fileName, String filePath) {
        GetRequest<File> request = OkGo.<File>get(apk.url);
        //这里第一个参数是tag，代表下载任务的唯一标识，传任意字符串都行，需要保证唯一,我这里用url作为了tag
        OkDownload.request(apk.url, request)
                .priority(apk.priority)
                .fileName(fileName)
                .folder(filePath)
                .extra1(apk)
                .save()
                .register(downloadListener)
                .restart();
    }
}
